import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';
import 'package:gourmet/color/hex.dart';
import 'package:gourmet/extensions/ex_widget.dart';
import 'package:gourmet/route/index.dart';
import 'package:gourmet/ui/draw_under_line.dart';
import 'package:gourmet/utils/colors.dart';
import 'package:gourmet/utils/radian.dart';
import 'package:gourmet/utils/styles.dart';
import 'package:package_info_plus/package_info_plus.dart';

class MineSettingController extends GetxController {
  RxBool isNews = RxBool(true);

  Rx<PackageInfo> packageInfo = Rx(PackageInfo(
    appName: 'Unknown',
    packageName: 'Unknown',
    version: 'Unknown',
    buildNumber: 'Unknown',
    buildSignature: 'Unknown',
    installerStore: 'Unknown',
  ));

  @override
  void onInit() {
    _initPackageInfo();
    super.onInit();
  }

  Future<void> _initPackageInfo() async {
    PackageInfo info = await PackageInfo.fromPlatform();
    packageInfo.value = info;
  }
}

class MineSettingPage extends GetView<MineSettingController> {
  const MineSettingPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: HexColor(ColorsUtils.colorF7f7),
      appBar: AppBar(
        backgroundColor: HexColor(ColorsUtils.colorF7f7),
        systemOverlayStyle: SystemUiOverlayStyle.dark,
        leading: IconButton(
            onPressed: Get.back,
            icon: Icon(
              CupertinoIcons.chevron_back,
              size: 18,
              color: HexColor(ColorsUtils.color0000),
            )),
        title: Text(
          '设置',
          softWrap: true,
          style: StylesUtils.customTextStyle(
              fontSize: StylesUtils.fontSize16,
              color: ColorsUtils.color0000,
              fontWeight: FontWeight.w700),
        ),
        centerTitle: true,
      ),
      body: SingleChildScrollView(
        child: Column(
          children: [
            Container(
              margin: const EdgeInsets.symmetric(vertical: 15),
              alignment: Alignment.center,
              child: Container(
                constraints:
                    const BoxConstraints.expand(width: 345, height: 100),
                decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(10)),
                child: Column(
                  children: [
                    DrawUnderLine(
                      strokeWidth: 2,
                      dx: 5,
                      dy: 5,
                      child: Container(
                        height: 50,
                        alignment: Alignment.centerLeft,
                        padding: const EdgeInsets.symmetric(horizontal: 15),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text(
                              '个人信息',
                              softWrap: true,
                              style: StylesUtils.customTextStyle(
                                  fontSize: StylesUtils.fontSize15,
                                  color: ColorsUtils.color0000),
                            ),
                            GestureDetector(
                              onTap: () {},
                              child: Icon(
                                CupertinoIcons.chevron_right,
                                color: HexColor(ColorsUtils.color9999),
                                size: 15,
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                    Container(
                      height: 50,
                      alignment: Alignment.centerLeft,
                      padding: const EdgeInsets.symmetric(horizontal: 15),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            '账号与安全',
                            softWrap: true,
                            style: StylesUtils.customTextStyle(
                                fontSize: StylesUtils.fontSize15,
                                color: ColorsUtils.color0000),
                          ),
                          GestureDetector(
                            onTap: () {},
                            child: Icon(
                              CupertinoIcons.chevron_right,
                              color: HexColor(ColorsUtils.color9999),
                              size: 15,
                            ),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ),
            Container(
              margin: const EdgeInsets.only(bottom: 30),
              alignment: Alignment.center,
              child: Container(
                width: 345,
                decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(10)),
                child: Column(
                  children: [
                    DrawUnderLine(
                      strokeWidth: 2,
                      dx: 5,
                      dy: 5,
                      child: Container(
                        height: 50,
                        alignment: Alignment.centerLeft,
                        padding: const EdgeInsets.symmetric(horizontal: 15),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text(
                              '新消息通知',
                              softWrap: true,
                              style: StylesUtils.customTextStyle(
                                  fontSize: StylesUtils.fontSize15,
                                  color: ColorsUtils.color0000),
                            ),
                            Obx(
                              () => GFToggle(
                                onChanged: (bool? val) {
                                  controller.isNews.value = val!;
                                },
                                value: controller.isNews.value,
                                type: GFToggleType.ios,
                                borderRadius: BorderRadius.circular(12),
                                enabledTrackColor:
                                    HexColor(ColorsUtils.colorFf64),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                    DrawUnderLine(
                      strokeWidth: 2,
                      dx: 5,
                      dy: 5,
                      child: Container(
                        height: 50,
                        alignment: Alignment.centerLeft,
                        padding: const EdgeInsets.symmetric(horizontal: 15),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text(
                              '隐私管理',
                              softWrap: true,
                              style: StylesUtils.customTextStyle(
                                  fontSize: StylesUtils.fontSize15,
                                  color: ColorsUtils.color0000),
                            ),
                            Icon(
                              CupertinoIcons.chevron_right,
                              color: HexColor(ColorsUtils.color9999),
                              size: 15,
                            ),
                          ],
                        ),
                      ).onTap(() {
                        Get.toNamed(Routes.privacyManageMent);
                      }),
                    ),
                    DrawUnderLine(
                      strokeWidth: 2,
                      dx: 5,
                      dy: 5,
                      child: Container(
                        height: 50,
                        alignment: Alignment.centerLeft,
                        padding: const EdgeInsets.symmetric(horizontal: 15),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text(
                              '本地缓存',
                              softWrap: true,
                              style: StylesUtils.customTextStyle(
                                  fontSize: StylesUtils.fontSize15,
                                  color: ColorsUtils.color0000),
                            ),
                            GestureDetector(
                              onTap: () {},
                              child: Text.rich(
                                TextSpan(
                                  children: [
                                    TextSpan(
                                      text: '26.08M ',
                                      style: StylesUtils.customTextStyle(
                                          fontSize: StylesUtils.fontSize15,
                                          color: ColorsUtils.color7979),
                                    ),
                                    WidgetSpan(
                                        child: Icon(
                                          CupertinoIcons.chevron_right,
                                          color:
                                              HexColor(ColorsUtils.color9999),
                                          size: 15,
                                        ),
                                        alignment: PlaceholderAlignment.middle)
                                  ],
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                    Container(
                      height: 50,
                      alignment: Alignment.centerLeft,
                      padding: const EdgeInsets.symmetric(horizontal: 15),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text.rich(
                            TextSpan(
                              children: [
                                TextSpan(
                                  text: '关于我们  ',
                                  style: StylesUtils.customTextStyle(
                                      fontSize: StylesUtils.fontSize15,
                                      color: ColorsUtils.color0000),
                                ),
                                WidgetSpan(
                                    child: CircleAvatar(
                                      backgroundColor:
                                          HexColor(ColorsUtils.colorFf64),
                                      radius: 6,
                                    ),
                                    alignment: PlaceholderAlignment.middle)
                              ],
                            ),
                          ),
                          Obx(
                            () => Text.rich(
                              TextSpan(
                                children: [
                                  TextSpan(
                                    text:
                                        'v${controller.packageInfo.value.version} ',
                                    style: StylesUtils.customTextStyle(
                                        fontSize: StylesUtils.fontSize15,
                                        color: ColorsUtils.color7979),
                                  ),
                                  WidgetSpan(
                                      child: Icon(
                                        CupertinoIcons.chevron_right,
                                        color: HexColor(ColorsUtils.color9999),
                                        size: 15,
                                      ),
                                      alignment: PlaceholderAlignment.middle)
                                ],
                              ),
                            ),
                          ),
                        ],
                      ),
                    ).onTap(() {
                      Get.toNamed(Routes.aboutUs);
                    }),
                  ],
                ),
              ),
            ),
            Center(
              child: Container(
                constraints:
                    const BoxConstraints.expand(width: 345, height: 45),
                alignment: Alignment.center,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(23),
                  gradient: LinearGradient(
                    colors: [
                      //linear-gradient(90deg, rgba(255, 153, 0, 1) 0%, rgba(255, 153, 0, 1) 0%, rgba(254, 70, 1, 1) 100%, rgba(254, 70, 1, 1) 100%)
                      ColorsUtils.rgba(255, 153, 0, 1),
                      ColorsUtils.rgba(255, 153, 0, 1),
                      ColorsUtils.rgba(254, 70, 1, 1),
                    ],
                    stops: const [0, 0, 1],
                    begin: Alignment.centerLeft,
                    end: Alignment.centerRight,
                    transform: GradientRotation(
                      RadianUtils.angleToRadian(90),
                    ),
                  ),
                ),
                child: Text(
                  '退出登录',
                  softWrap: true,
                  style: StylesUtils.customTextStyle(
                      fontSize: StylesUtils.fontSize16),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}
